package theDrunkenKiss.code.presentation;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Gravity;
import android.view.OrientationEventListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class TurnTheDeviceActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new TutrnTheDeviceScreen(this));

	}

	class TutrnTheDeviceScreen extends ScrollView {

		private LinearLayout linearLayout;
		private TextView testtext;
		private OrientationEventListener orientationListener;
		private Activity context;
		private int orientation;
		private Intent playActivity;

		public TutrnTheDeviceScreen(Activity context) {

			super(context);
			this.context = context;

			this.linearLayout = new LinearLayout(context);
			this.testtext = new TextView(context);
			this.testtext.setText("turn your device");

			this.linearLayout.addView(this.testtext);

			this.addView(this.linearLayout);

			orientationListener = new OrientationEventListener(context,
					SensorManager.SENSOR_DELAY_NORMAL) {
				

				@Override
				public void onOrientationChanged(int orientation) {

					if (orientation != -1) {

						testtext.setText("wert = " + orientation);

						if (orientation == 270) {
							
							orientationListener.disable();

							//new activity
						startPlayactivity();
						
						 // ends this one
						//killActivity();

						
						}

					}
				}
			};

			orientationListener.enable();

		}
		
		private void startPlayactivity() {
			
			playActivity = new Intent(this.context,
					PlaysActivity.class);

			context.startActivity(playActivity);
		}

		private void killActivity() {
			
			this.context.finish();
		}
	}
}
